package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
    Code    int         `json:"code"`
    Message string      `json:"message"`
    Data    interface{} `json:"data"`
}

// 服务端错误
func RespServerErr(c *gin.Context, err error) {
	c.JSON(http.StatusInternalServerError, gin.H{
		"code": http.StatusInternalServerError,
		"msg":  "服务端错误",
		"data": err.Error(),
	})
	return
}

func Error(c *gin.Context, code int, message string, data interface{}) {
	c.JSON(http.StatusBadRequest, gin.H{
		"code":    code,
		"message": message,
		"data":    data,
	})
}
func Success(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, gin.H{
		"code":    http.StatusOK,
		"message": "success",
		"data":    data,
	})
}
